#ifndef LOADJSONFILE_H
#define LOADJSONFILE_H
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <sys/mman.h>
#include <sys/stat.h>
#include <cJSON/cJSON.h>

cJSON *load_json_file(char *conf)
{
	int fd;
	char *p;
	cJSON *cj;
	struct stat st;

	if(!conf)
		return NULL;
	fd = open(conf, O_RDWR);
	if(fd <= 0){
		printf("conf file not found.\n");
		return NULL;
	}

	if(fstat(fd, &st)){
		printf("get stat error!\n");
		return NULL;
	}

	p = mmap(NULL,st.st_size, PROT_READ, MAP_SHARED, fd, 0);
	cj = cJSON_Parse(p);
	munmap(p,st.st_size);
	close (fd);

	return cj;
}

#endif
